#!/bin/sh
. rt.comm
mkdir /tmp/rt -p

if [ -z "$1" ];then
    config_cont=`rtinfo`
    if [ "$config_cont" == "" ]; then 
        rt_noconf
        exit 0  
    fi

    ls_para=""

    rt_diff_ls $ls_para 
    
    exit 0
elif [ "$1" == "-v" ];then
    cur_pwd=`pwd`
    base_name=`basename $2` 
    #echo base_name=$base_name
    target_dir=`dirname $2` #must use this ,or can't diff more than one files
    #target_dir=${1%/*}
    #echo target_dir=$target_dir

    if [ -d "$target_dir/$base_name" ];then
        #echo $target_dir/$base_name is a directory
        ls_para=$base_name
    else
        #echo $target_dir/$base_name is not a directory
        ls_para=`ls $2| xargs -i basename {}`
        #ls_para=${*##*/}
    fi
    #echo ls_para=$ls_para


    #echo cd "$target_dir"
    cd "$target_dir"

    config_cont=`rtinfo`
    if [ "$config_cont" == "" ]; then 
        rt_noconf
        cd "$cur_pwd"
        exit 0  
    fi
 
    rt_diff_file $ls_para 
    
    #echo cd "$cur_pwd"
    cd "$cur_pwd"
    
    exit 0

else
    cur_pwd=`pwd`
    base_name=`basename $1` 
    #echo base_name=$base_name
    target_dir=`dirname $1` #must use this ,or can't diff more than one files
    #target_dir=${1%/*}
    #echo target_dir=$target_dir



    if [ -d "$target_dir/$base_name" ];then
        #echo $target_dir/$base_name is a directory
        ls_para=$base_name
    else
        #echo $target_dir/$base_name is not a directory
        ls_para=`ls $*| xargs -i basename {}`
        #ls_para=${*##*/}
    fi
    #echo ls_para=$ls_para


    #echo cd "$target_dir"
    cd "$target_dir"

    config_cont=`rtinfo`
    if [ "$config_cont" == "" ]; then 
        rt_noconf
        cd "$cur_pwd"
        exit 0  
    fi
 
    rt_diff_ls $ls_para 
    
    #echo cd "$cur_pwd"
    cd "$cur_pwd"
    
    exit 0
fi

exit 0
